package com.abvnet.project.water.customer.controller;

import com.abvnet.common.utils.security.ShiroUtils;
import com.abvnet.framework.web.controller.BaseController;
import com.abvnet.framework.web.page.TableDataInfo;
import com.abvnet.project.water.project.domain.ProjectInfo;
import com.abvnet.project.water.project.domain.ProjectMicrobial;
import com.abvnet.project.water.project.service.*;
import com.abvnet.project.water.sewage.service.ISewageFlowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/customer/projectInfo")
public class CustomerProjectInfoController extends BaseController {

    private String prefix = "customer/projectInfo";

    @Autowired
    private IProjectInfoService projectInfoService;

    @Autowired
    private IProjectFlowService projectFlowService;

    @Autowired
    private IProjectTechService projectTechService;

    @Autowired
    private IProjectEqpService projectEqpService;

    @Autowired
    private IProjectWaterService projectWaterService;

    @Autowired
    private IProjectMicroService projectMicroService;

    @Autowired
    private IProjectPharmService projectPharmService;

    @Autowired
    private IProjectMicrobialService projectMicrobialService;

    @Autowired
    private ISewageFlowService sewageFlowService;

    @GetMapping()
    public String projectInfo() {
        return prefix + "/list";
    }

    /**
     * 查询项目列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProjectInfo projectInfo) {
        projectInfo.setDeptId(ShiroUtils.getSysUser().getDeptId());
        startPage();
        List<ProjectInfo> list = projectInfoService.selectCustomerProjectInfoList(projectInfo);
        return getDataTable(list);
    }


    @GetMapping("/info/{projectId}")
    public String info(@PathVariable("projectId") Long projectId, ModelMap mmap) {
        mmap.put("projectInfo", projectInfoService.selectProjectInfoById(projectId));
        return prefix + "/info";
    }

    @GetMapping("/flow/{projectId}")
    public String flow(@PathVariable("projectId") Long projectId, ModelMap mmap) {
        mmap.put("projectFlow", projectFlowService.selectProjectFlowByProjectId(projectId));
        return prefix + "/flow";
    }

    @GetMapping("/tech/{projectId}")
    public String tech(@PathVariable("projectId") Long projectId, ModelMap mmap) {
        mmap.put("sfList", sewageFlowService.selectSewageFlowListByProjectId(projectId));
        mmap.put("projectTech", projectTechService.selectProjectTechByProjectId(projectId));
        return prefix + "/tech";
    }

    @GetMapping("/eqp/{projectId}")
    public String eqp(@PathVariable("projectId") Long projectId, ModelMap mmap) {
        mmap.put("projectEqp", projectEqpService.selectProjectEqpByProjectId(projectId));
        return prefix + "/eqp";
    }

    @GetMapping("/water/{projectId}")
    public String water(@PathVariable("projectId") Long projectId, ModelMap mmap) {
        mmap.put("projectWater", projectWaterService.selectProjectWaterByProjectId(projectId));
        return prefix + "/water";
    }

    @GetMapping("/micro/{projectId}")
    public String micro(@PathVariable("projectId") Long projectId, ModelMap mmap) {
        mmap.put("sfList", sewageFlowService.selectSewageFlowListByProjectId(projectId));
        mmap.put("mList", projectMicrobialService.selectMicroList());
        mmap.put("projectMicro", projectMicroService.selectProjectMicroByProjectId(projectId));
        return prefix + "/micro";
    }

    @GetMapping("/pharm/{projectId}")
    public String pharm(@PathVariable("projectId") Long projectId, ModelMap mmap) {
        mmap.put("sfList", sewageFlowService.selectSewageFlowListByProjectId(projectId));
        mmap.put("csList", projectMicrobialService.selectProjectMicrobialList(ProjectMicrobial.builder().microbialType("2").microbialCategory("1").build()));
        mmap.put("phosList", projectMicrobialService.selectProjectMicrobialList(ProjectMicrobial.builder().microbialType("2").microbialCategory("2").build()));
        mmap.put("flocList", projectMicrobialService.selectProjectMicrobialList(ProjectMicrobial.builder().microbialType("2").microbialCategory("3").build()));
        mmap.put("oxidList", projectMicrobialService.selectProjectMicrobialList(ProjectMicrobial.builder().microbialType("2").microbialCategory("4").build()));
        mmap.put("otherList", projectMicrobialService.selectProjectMicrobialList(ProjectMicrobial.builder().microbialType("2").microbialCategory("6").build()));
        mmap.put("projectPharm", projectPharmService.selectProjectPharmByProjectId(projectId));
        return prefix + "/pharm";
    }
}